package com.garyme.hycloud.model;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
@Data
public class HyFileBase {
    private String currentPath;
    private List<HyFile> fileList;
    private Integer total;
    private List<HyBreadcrumb> dirList;

    public void setCurrentPath(String currentPath) {
        this.dirList = new ArrayList<>();
        if(currentPath.equals("/")) {
            this.dirList.add(HyBreadcrumb.builder().name("/").path("/").build());
        }else{
            this.dirList.add(HyBreadcrumb.builder().name("/").path("/").build());
            String[] res = currentPath.split("/");
            String targetName = "";
            String targetPath = "";
            int idx = 0;
            for(int i=1;i<res.length;i++){
                targetName = res[i];
                targetPath = currentPath.substring(0,idx+=res[i].length()+1);
                this.dirList.add(HyBreadcrumb.builder().name(targetName).path(targetPath).build());
            }
        }
        this.currentPath = currentPath;
    }
}
